package com.sgb.kjwl.view.ui.activity.self.authentication;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.sgb.capital.view.widget.BaseRecyclerViewAdapterHelper.BaseQuickAdapter;
import com.sgb.capital.view.widget.BaseRecyclerViewAdapterHelper.viewholder.BaseViewHolder;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityTeamAuthDetailBinding;
import com.sgb.kjwl.di.self.DaggerSelfComponent;
import com.sgb.kjwl.di.self.SelfModule;
import com.sgb.kjwl.model.entity.UserMsgEntity;
import com.sgb.kjwl.model.entity.self.TeamPerson;
import com.sgb.kjwl.model.entity.user.AuthDetailEntity;
import com.sgb.kjwl.view.ui.adapter.self.mine.TeamAuthAdapter;
import com.sgb.kjwl.viewmodel.self.TeamAuthDetailModel;
import com.sgb.kjwl.viewmodel.self.UserAuthDetailModel;
import com.swgk.core.base.di.AppComponent;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * 团队认证详情
 */
public class TeamAuthDetailActivity extends AppActivity {
    private ActivityTeamAuthDetailBinding binding;
    String userNo;

    @Inject
    TeamAuthDetailModel viewModel;

    private TeamAuthAdapter adapter;

    private List<TeamPerson> mlist=new ArrayList<>();
    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerSelfComponent.builder().appComponent(appComponent).selfModule(new SelfModule(this)).build().inject(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    //设置状态栏为暗
    @Override
    protected boolean statusBarDark() {
        return true;
    }

    @Override
    protected void initView() {
        //双向绑定Activity和View
        binding = DataBindingUtil.setContentView(TeamAuthDetailActivity.this, R.layout.activity_team_auth_detail);
        binding.nsView.setVisibility(View.INVISIBLE);
        userNo = getIntent().getStringExtra("userNo");
        viewModel.getUserInfo(userNo);

        binding.include.titleView.setText("认证详情");
        binding.include.ivBack.setOnClickListener(view -> finish());
        binding.itvItemAdminCard.setEnable(false);
        binding.itvItemAdminName.setEnable(false);
        binding.itvItemAdminPhone.setEnable(false);
        adapter =new TeamAuthAdapter(R.layout.item_team_auth_detail,mlist);
        LinearLayoutManager linearLayoutManager =new LinearLayoutManager(this){
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        binding.mRecyclerView.setLayoutManager(linearLayoutManager);
        binding.mRecyclerView.setAdapter(adapter);
        binding.llReAuthen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                 TeamAuthActivity.start(TeamAuthDetailActivity.this,userNo);
                 finish();
            }
        });
    }

    public static void start(Context context, String userNo) {
        Intent intent = new Intent(context, TeamAuthDetailActivity.class);
        intent.putExtra("userNo", userNo);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(intent);
    }

    public void showDetail(AuthDetailEntity entity) {
        binding.zhuyin.setText(entity.getNewMainBusinessName());
        binding.nsView.setVisibility(View.VISIBLE);
        binding.setEntity(entity);
        if (entity.getRealNameUserDTO() != null){
            binding.itvItemAdminPhone.setContent(entity.getRealNameUserDTO().getPhone());
            binding.itvItemAdminName.setContent(entity.getRealNameUserDTO().getRealName());
            binding.itvItemAdminCard.setContent(entity.getRealNameUserDTO().getIdentityCard());
        }
        switch (entity.getTeamAuthStatus()){
            case 1:
                binding.logo.setImageResource(R.mipmap.authen_ing);
                binding.type.setText("审核中");
                binding.why.setVisibility(View.GONE);
                binding.llReAuthen.setVisibility(View.GONE);
                break;
            case 2:
                binding.logo.setImageResource(R.mipmap.authen_success);
                binding.type.setText("认证成功");
                binding.why.setVisibility(View.GONE);
                binding.llReAuthen.setVisibility(View.GONE);
                break;
            case 3:
                binding.logo.setImageResource(R.mipmap.authen_fail);
                binding.type.setText("审核失败");
                binding.why.setVisibility(View.VISIBLE);
                binding.llReAuthen.setVisibility(View.VISIBLE);
                binding.why.setText("失败原因："+entity.getRemake());
                break;
        }
        mlist.addAll(entity.getPersonList());
        adapter.notifyDataSetChanged();
    }
    public class TeamAuthAdapter extends BaseQuickAdapter<TeamPerson, BaseViewHolder> {

        public TeamAuthAdapter(int layoutResId, @Nullable List<TeamPerson> data) {
            super(layoutResId, data);
        }

        @Override
        protected void convert(@NonNull BaseViewHolder holder, TeamPerson item) {
            TextView name = holder.getView(R.id.name);
            TextView phone = holder.getView(R.id.phone);
            TextView zhuanye = holder.getView(R.id.zhuanye);
            TextView minzu = holder.getView(R.id.minzu);
            TextView jiguan = holder.getView(R.id.jiguan);
            TextView shengri = holder.getView(R.id.shengri);
            holder.setText(R.id.number, (holder.getPosition() + 1) + "");
            name.setText(item.getName());
            phone.setText(item.getPhone());
            zhuanye.setText(item.getMajor());
            minzu.setText(item.getNation());
            jiguan.setText(item.getDomicile());
            if (item.getBirthDate()!=null) {
                shengri.setText(item.getBirthDate());
            } else {
                shengri.setText("");
            }
        }
    }
}
